﻿$G.pin = {
	_hp: "",
	g: null, tbPin: function () { if (!this.g) this.g = $(".tbPin"); return this.g; },
	h: null, num_key: function () { if (!this.h) this.h = $(".num-key"); return this.h; },
	i: null, btnApprove: function () { if (!this.i) this.i = $("#btnApprove"); return this.i; },

	initialize: function () {
		this.num_key().off("touchstart click").on("touchstart click", function (e) {
			e.stopPropagation(); e.preventDefault();
			$G.pin.numKeyTouch.call($G.pin, $(this).val());
		});
	},

	clearPin: function() {
		$G.pin.numKeyTouch('C');
	},

	numKeyTouch: function (key) {
		var l = this._hp.length;
		switch (key) { case 'D': this._hp = this._hp.slice(0, -1); break; case 'C': this._hp = ""; break; default: if (key !== ' ' && l < 4) this._hp += key; break; }

		l = this._hp.length;

		this.tbPin().slice(0, l).text('✱');
		this.tbPin().slice(l).text('●');

		this.btnApprove().toggle(l === 4);
	},
}